s/PixelFormat/Format/g
authorØyvind Kolås <ok@src.gnome.org>
Wed, 24 Aug 2005 15:09:55 +0000 (15:09 +0000)
committerØyvind Kolås <ok@src.gnome.org>
Wed, 24 Aug 2005 15:09:55 +0000 (15:09 +0000)
42 files changed:
ChangeLog
babl/babl-classes.c
babl/babl-classes.h
babl/babl-component.c
babl/babl-conversion.c
babl/babl-db.h
babl/babl-fish.c
babl/babl-fish.h
babl/babl-format.c
babl/babl-format.h
babl/babl-ids.h
babl/babl-image.c
babl/babl-image.h
babl/babl-internal.c
babl/babl-internal.h
babl/babl-introspect.c
babl/babl-model.c
babl/babl-model.h
babl/babl-pixel-format.c
babl/babl-pixel-format.h
babl/babl-sanity.c
babl/babl-sanity.h
babl/babl-type.c
babl/babl.c
babl/babl.h
babl/base/model-cmyk.c
babl/base/model-gray.c
babl/base/model-lab.c
babl/base/model-rgb.c
babl/base/model-ycbcr.c
babl/base/type-u16.c
babl/base/type-u8.c
tests/Makefile.am
tests/babl-html-dump.c
tests/babl_class_name.c
tests/float_to_u8.c
tests/grayscale_to_rgb.c
tests/rgb_to_lab_to_rgb.c
tests/rgb_to_ycbcr.c
tests/rgb_to_ycbcr_to_rgb.c
tests/srgb_to_lab_u8.c [new file with mode: 0644]
tests/u8_to_float.c

index e6e92d9d6077e6051045b841e3d5a2a04a4b78e4..d21ffb0fb9f8a4bc60b8046fe548d9f066bdfa69 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,50 @@
+2005-08-24  Øyvind Kolås  <pippin@gimp.org>
+
+       * babl/babl-classes.c,
+       * babl/babl-classes.h,
+       * babl/babl-component.c,
+       * babl/babl-conversion.c,
+       * babl/babl-db.h,
+       * babl/babl-fish.c,
+       * babl/babl-fish.h,
+       * babl/babl-image.c,
+       * babl/babl-image.h,
+       * babl/babl-internal.h,
+       * babl/babl-introspect.c,
+       * babl/babl-model.c,
+       * babl/babl-model.h,
+       * babl/babl-pixel-format.c,
+       * babl/babl-pixel-format.h,
+       * babl/babl-sanity.c,
+       * babl/babl-sanity.h,
+       * babl/babl-type.c,
+       * babl/babl.c,
+       * babl/babl.h,
+       * babl/base/model-cmyk.c,
+       * babl/base/model-gray.c,
+       * babl/base/model-lab.c,
+       * babl/base/model-rgb.c,
+       * babl/base/model-ycbcr.c,
+       * tests/Makefile.am,
+       * tests/babl-html-dump.c,
+       * tests/babl_class_name.c,
+       * tests/float_to_u8.c,
+       * tests/grayscale_to_rgb.c,
+       * tests/rgb_to_lab_to_rgb.c,
+       * tests/rgb_to_ycbcr.c,
+       * tests/rgb_to_ycbcr_to_rgb.c,
+       * tests/u8_to_float.c: s/PixelFormat/Format/ (etc in other cases),
+       Made BablFish be more polymorphic (accept
+       format names as well as BablFormats).
+       * babl/babl-ids.h: reorganized, some renames. 
+
+       * tests/srgb_to_lab_u8.c: new test for 8bit CIE Lab format (reference
+       data not correct yet).
+
+       * babl/base/type-u16.c,
+       * babl/base/type-u8.c: Added CIE fixed point data types.
+
+
 2005-08-24  Øyvind Kolås  <pippin@gimp.org>
 
        * docs/babl.css: Added code highlighting classes.
index 8f2376d3e6f488b51eaf3560dd276d0bf88af8b7..479ac68aed1dc6cdace06c9e3e4dbcaa5b0b1f4a 100644 (file)
@@ -28,13 +28,13 @@ static const char *class_names[] =
     "BablSampling",
     "BablComponent",
     "BablModel",
-    "BablPixelFormat",
+    "BablFormat",
     "BablConversion",
     "BablConversionType",
     "BablConversionTypePlanar",
     "BablConversionModelPlanar",
-    "BablConversionPixelFormat",
-    "BablConversionPixelFormatPlanar",
+    "BablConversionFormat",
+    "BablConversionFormatPlanar",
     "BablFish",
     "BablFishReference",
     "BablImage",
index 8bd024d800e6790032c408ab64a4ff0b6502f53d..390a270d73250652df4ed76cf1ea7fc3bf5cd2b0 100644 (file)
 #ifndef _BABL_CLASSES_H
 #define _BABL_CLASSES_H
 
-/* Type and PixelFormat */
+/* Type and Format */
 typedef void (*BablFuncLinear)    (void  *src,
                                    void  *dst,
                                    int    n);
 
-/* TypePlanar, ModelPlanar and PixelFormatPlanar */
+/* TypePlanar, ModelPlanar and FormatPlanar */
 typedef void (*BablFuncPlanar)    (int    src_bands,
                                    void  *src[],
                                    int    src_pitch[],
@@ -60,14 +60,14 @@ typedef enum {
   BABL_SAMPLING,
   BABL_COMPONENT,
   BABL_MODEL,
-  BABL_PIXEL_FORMAT,
+  BABL_FORMAT,
 
   BABL_CONVERSION,
   BABL_CONVERSION_TYPE,
   BABL_CONVERSION_TYPE_PLANAR,
   BABL_CONVERSION_MODEL_PLANAR,
-  BABL_CONVERSION_PIXEL_FORMAT,
-  BABL_CONVERSION_PIXEL_FORMAT_PLANAR,
+  BABL_CONVERSION_FORMAT,
+  BABL_CONVERSION_FORMAT_PLANAR,
 
   BABL_FISH,
   BABL_FISH_REFERENCE,
@@ -124,12 +124,12 @@ typedef struct
 typedef struct
 {
   BablConversion conversion;
-} BablConversionPixelFormat;
+} BablConversionFormat;
 
 typedef struct
 {
   BablConversion conversion;
-} BablConversionPixelFormatPlanar;
+} BablConversionFormatPlanar;
 
 typedef struct
 {
@@ -199,7 +199,7 @@ typedef struct
   BablComponent  **component;
   BablType       **type;
   BablSampling   **sampling;
-} BablPixelFormat;
+} BablFormat;
 
 typedef struct
 {
@@ -251,7 +251,7 @@ typedef union
   BablSampling      sampling;
   BablComponent     component;
   BablModel         model;
-  BablPixelFormat   pixel_format;
+  BablFormat        format;
   BablConversion    conversion;
   BablFish          fish;
   BablFishReference reference_fish;
index 6817bddd49fd19d90db9d16d62ed3c5bad57e14b..6c86eb458517ece3bc1492d1a8f54da8b194bcfb 100644 (file)
@@ -108,7 +108,7 @@ babl_component_new (const char *name,
       
       else
         {
-          babl_log ("%s(): unhandled parameter '%s' for pixel_format '%s'",
+          babl_log ("%s(): unhandled parameter '%s' for format '%s'",
                     __FUNCTION__, arg, name);
           exit (-1);
         }
index 0c5ccd511130368d517b66c5e03d96f2bbda0b58..bc9a69ea9bceddc5d150c4f619552bb133157168 100644 (file)
@@ -85,17 +85,17 @@ conversion_new (const char        *name,
                       __FUNCTION__);
           }
         break;
-      case BABL_PIXEL_FORMAT:
+      case BABL_FORMAT:
         if (linear)
           {
-            babl = babl_calloc (sizeof (BablConversionPixelFormat), 1);
-            babl->class_type = BABL_CONVERSION_PIXEL_FORMAT;
+            babl = babl_calloc (sizeof (BablConversionFormat), 1);
+            babl->class_type = BABL_CONVERSION_FORMAT;
             babl->conversion.function.linear = linear;
           }
         else if (planar)
           {
-            babl = babl_calloc (sizeof (BablConversionPixelFormatPlanar), 1);
-            babl->class_type = BABL_CONVERSION_PIXEL_FORMAT_PLANAR;
+            babl = babl_calloc (sizeof (BablConversionFormatPlanar), 1);
+            babl->class_type = BABL_CONVERSION_FORMAT_PLANAR;
             babl->conversion.function.planar = planar;
           }
         else if (planar_bit)
@@ -208,7 +208,7 @@ babl_conversion_new (const char *name,
         }
       else
         {
-          babl_log ("%s(): unhandled parameter '%s' for pixel_format '%s'",
+          babl_log ("%s(): unhandled parameter '%s' for format '%s'",
                     __FUNCTION__, arg, name);
           exit (-1);
         }
index f0b4abe54862523b6a085232f9cead24c8651cd3..270634db367f5c6e203212a07ae6102e513a4ddc 100644 (file)
 #define DB_INCREMENT_SIZE  16
 #endif
 
+static inline int hash (char *str)
+{
+  int ret = 0;
+  int i   = 1;
+
+  while (*str)
+    ret = (ret + ( i++ * (*str ++ & 31 ))) % 199;
+  return ret;
+}
 
 /* file scope variables, for this .c file's database */
 static int    db_size     = 0;
index 678af6a760db8436c7e17cba3fa55b7175b81795..b349f2790030b4e9fcd596456bcff672a47d50b2 100644 (file)
@@ -124,9 +124,9 @@ babl_fish_reference_new (Babl *source,
   assert (BABL_IS_BABL (source));
   assert (BABL_IS_BABL (destination));
 
-  assert (source->class_type == BABL_PIXEL_FORMAT ||
+  assert (source->class_type == BABL_FORMAT ||
           source->class_type == BABL_MODEL);
-  assert (destination->class_type == BABL_PIXEL_FORMAT ||
+  assert (destination->class_type == BABL_FORMAT ||
           destination->class_type == BABL_MODEL);
 
   babl                   = babl_calloc (sizeof (BablFishReference), 1);
@@ -136,53 +136,54 @@ babl_fish_reference_new (Babl *source,
   babl->fish.source      = (union Babl*)source;
   babl->fish.destination = (union Babl*)destination;
  
-  if (source->class_type == BABL_PIXEL_FORMAT)
+  if (source->class_type == BABL_FORMAT)
     {
       babl->reference_fish.type_to_double =
          babl_conversion_find (
-            source->pixel_format.type[0],
+            source->format.type[0],
             babl_type_id (BABL_DOUBLE)
          );
 
       babl->reference_fish.model_to_rgba =
         babl_conversion_find (
-            source->pixel_format.model,
+            source->format.model,
             babl_model_id (BABL_RGBA)
         );
 
       babl->reference_fish.rgba_to_model =
         babl_conversion_find (
             babl_model_id (BABL_RGBA),
-            destination->pixel_format.model
+            destination->format.model
         );
 
       babl->reference_fish.double_to_type =
         babl_conversion_find (
             babl_type_id (BABL_DOUBLE),
-            destination->pixel_format.type[0]
+            destination->format.type[0]
         );
     }
   else if (source->class_type == BABL_MODEL)
     { 
       babl->reference_fish.type_to_double = NULL;
 
+      babl_log ("EEEEEEEEEEEEEEEEEEEEK!%s","!!!!");
 
       babl->reference_fish.model_to_rgba =
         babl_conversion_find (
-            source->pixel_format.model,
+            source->format.model,
             babl_model_id (BABL_RGBA)
         );
 
       babl->reference_fish.rgba_to_model =
         babl_conversion_find (
             babl_model_id (BABL_RGBA),
-            destination->pixel_format.model
+            destination->format.model
         );
 
       babl->reference_fish.double_to_type =
         babl_conversion_find (
             babl_type_id (BABL_DOUBLE),
-            destination->pixel_format.type[0]
+            destination->format.type[0]
         );
     }
 
@@ -209,10 +210,48 @@ babl_fish_reference_new (Babl *source,
 }
 
 Babl *
-babl_fish (Babl *source,
-           Babl *destination)
+babl_fish (void *source,
+           void *destination)
 {
-  return babl_fish_reference_new (source, destination);
+  Babl *source_format = NULL;
+  Babl *destination_format = NULL;
+
+  assert (source);
+  assert (destination);
+
+  if (BABL_IS_BABL (source))
+    {
+      source_format = source;
+    }
+
+  if (!source_format)
+    {
+      source_format = babl_format ((char*)source);
+    }
+
+  if (!source_format)
+    {
+      babl_log ("%s(%p, %p) source format invalid", 
+         __FUNCTION__, source, destination);
+    }
+
+  if (BABL_IS_BABL (destination))
+    {
+      destination_format = destination;
+    }
+
+  if (!destination_format)
+    {
+      destination_format = babl_format ((char*)destination);
+    }
+
+  if (!destination_format)
+    {
+      babl_log ("%s(%p, %p) destination format invalid",
+         __FUNCTION__, source, destination);
+    }
+  
+  return babl_fish_reference_new (source_format, destination_format);
 }
 
 void *fooA;
@@ -221,11 +260,14 @@ void *fooC;
 
 #define BABL_MAX_BANDS   32
 
+/* should perhaps have been babl_fish_process, but the public api
+ * is shorther and makes sense for the API
+ */
 int
-babl_fish_process (Babl *babl,
-                   void *source,
-                   void *destination,
-                   int   n)
+babl_process (Babl *babl,
+              void *source,
+              void *destination,
+              int   n)
 {
   Babl *imageA;
   Babl *imageB;
@@ -253,11 +295,11 @@ babl_fish_process (Babl *babl,
  
   babl_conversion_process (babl->reference_fish.type_to_double,
                            source, fooA,
-                           n * BABL(babl->fish.source)->pixel_format.bands);
+                           n * BABL(babl->fish.source)->format.bands);
 
   /* calculate planar representation of fooA, and fooB */
 
-  imageA = babl_image_new_from_linear (fooA, BABL(BABL((babl->fish.source)) -> pixel_format.model));
+  imageA = babl_image_new_from_linear (fooA, BABL(BABL((babl->fish.source)) -> format.model));
   imageB = babl_image_new_from_linear (fooB, babl_model_id (BABL_RGBA));
   /* transform fooA into fooB fooB is rgba double */
 
@@ -274,7 +316,7 @@ babl_fish_process (Babl *babl,
   imageB = babl_image_new_from_linear (
               fooB, babl_model_id (BABL_RGBA));
   imageC = babl_image_new_from_linear (
-              fooA, BABL(BABL((babl->fish.destination))->pixel_format.model));
+              fooA, BABL(BABL((babl->fish.destination))->format.model));
 
   babl_conversion_process (babl->reference_fish.rgba_to_model,
                            imageB, imageC,
@@ -283,7 +325,7 @@ babl_fish_process (Babl *babl,
   /* working directly on linear buffers */
   babl_conversion_process (babl->reference_fish.double_to_type,
                            fooA, destination,
-                           n * BABL(babl->fish.destination)->pixel_format.bands);
+                           n * BABL(babl->fish.destination)->format.bands);
 
   babl_free (imageB);
   babl_free (imageC);
index ad5235fe9a7c29396f1fa0cc4000f76d33ab181a..5bb25532cb5ec84ef52da6185bcb54d03a210865 100644 (file)
 BABL_DEFINE_CLASS_NO_NEW_NO_ID(babl_fish)
 
 /** create a new BablFish capable of translating between the pixel
- *  formats given in source and destination. (use babl_pixel_format (string))
+ *  formats given in source and destination. (use babl_format (string))
  */
-Babl * babl_fish              (Babl *source,
-                               Babl *destination);
+Babl * babl_fish              (void *source,
+                               void *destination);
 
 /* Transform n pixels from source into destination,
  * source and destination can be pointers to linear buffers
  * (or at a later stage of babl development BablImages)
  */
-int    babl_fish_process      (Babl *babl_fish,
+int    babl_process           (Babl *babl_fish,
                                void *source,
                                void *destination,
                                int   n);
index d10fb5a95ec22c9359a7ec613fb0db0f3cdfe653..1619a817974734807bce885b26aea7cbbba6d6a5 100644 (file)
 #define BABL_MAX_BANDS 32
 
 static int 
-each_babl_pixel_format_destroy (Babl *babl,
+each_babl_format_destroy (Babl *babl,
                                 void *data)
 {
-  babl_free (babl->pixel_format.from);
-  babl_free (babl->pixel_format.to);
+  babl_free (babl->format.from);
+  babl_free (babl->format.to);
   babl_free (babl);
 
   return 0;  /* continue iterating */
 }
 
 static Babl *
-pixel_format_new (const char     *name,
+format_new (const char     *name,
                   int             id,
                   int             planar,
                   int             bands,
@@ -53,7 +53,7 @@ pixel_format_new (const char     *name,
   int              band;
 
   /* allocate all memory in one chunk */
-  babl  = babl_calloc (sizeof (BablPixelFormat) +
+  babl  = babl_calloc (sizeof (BablFormat) +
                        strlen (name) + 1 +
                        sizeof (BablComponent*) * (bands+1) +
                        sizeof (BablSampling*)  * (bands+1) +
@@ -61,34 +61,34 @@ pixel_format_new (const char     *name,
                        sizeof (int)            * (bands+1) +
                        sizeof (int)            * (bands+1),1);
 
-  babl->pixel_format.component = ((void *)babl) + sizeof (BablPixelFormat);
-  babl->pixel_format.type      = ((void *)babl->pixel_format.component) + sizeof (BablComponent*) * (bands+1);
-  babl->pixel_format.sampling  = ((void *)babl->pixel_format.type)      + sizeof (BablType*) * (bands+1);
-  babl->instance.name          = ((void *)babl->pixel_format.sampling)  + sizeof (BablSampling*) * (bands+1);
+  babl->format.component = ((void *)babl) + sizeof (BablFormat);
+  babl->format.type      = ((void *)babl->format.component) + sizeof (BablComponent*) * (bands+1);
+  babl->format.sampling  = ((void *)babl->format.type)      + sizeof (BablType*) * (bands+1);
+  babl->instance.name          = ((void *)babl->format.sampling)  + sizeof (BablSampling*) * (bands+1);
   
-  babl->class_type    = BABL_PIXEL_FORMAT;
+  babl->class_type    = BABL_FORMAT;
   babl->instance.id   = id;
   strcpy (babl->instance.name, name);
 
-  babl->pixel_format.model  = model;
-  babl->pixel_format.bands  = bands;
-  babl->pixel_format.planar = planar;
+  babl->format.model  = model;
+  babl->format.bands  = bands;
+  babl->format.planar = planar;
 
   for (band=0; band < bands; band++)
     {
-      babl->pixel_format.component[band] = component[band];
-      babl->pixel_format.type[band] = type[band];
-      babl->pixel_format.sampling[band] = sampling[band];
+      babl->format.component[band] = component[band];
+      babl->format.type[band] = type[band];
+      babl->format.sampling[band] = sampling[band];
     }
-  babl->pixel_format.component[band] = NULL;
-  babl->pixel_format.type[band]      = NULL;
-  babl->pixel_format.sampling[band]  = NULL;
+  babl->format.component[band] = NULL;
+  babl->format.type[band]      = NULL;
+  babl->format.sampling[band]  = NULL;
 
   return babl;
 }
 
 Babl *
-babl_pixel_format_new (const char *name,
+babl_format_new (const char *name,
                        ...)
 {
   va_list varg;
@@ -153,13 +153,13 @@ babl_pixel_format_new (const char *name,
                   model = (BablModel*)arg;
                   break;
               case BABL_INSTANCE:
-              case BABL_PIXEL_FORMAT:
+              case BABL_FORMAT:
               case BABL_CONVERSION:
               case BABL_CONVERSION_TYPE:
               case BABL_CONVERSION_TYPE_PLANAR:
               case BABL_CONVERSION_MODEL_PLANAR:
-              case BABL_CONVERSION_PIXEL_FORMAT:
-              case BABL_CONVERSION_PIXEL_FORMAT_PLANAR:
+              case BABL_CONVERSION_FORMAT:
+              case BABL_CONVERSION_FORMAT_PLANAR:
               case BABL_FISH:
               case BABL_FISH_REFERENCE:
               case BABL_IMAGE:
@@ -188,7 +188,7 @@ babl_pixel_format_new (const char *name,
       
       else
         {
-          babl_log ("%s: unhandled parameter '%s' for pixel_format '%s'",
+          babl_log ("%s: unhandled parameter '%s' for format '%s'",
                     __FUNCTION__, arg, name);
           exit (-1);
         }
@@ -197,7 +197,7 @@ babl_pixel_format_new (const char *name,
   va_end   (varg);
 
 
-  babl = pixel_format_new (name, id,
+  babl = format_new (name, id,
                            planar, bands, model,
                            component, sampling, type);
 
@@ -208,9 +208,9 @@ babl_pixel_format_new (const char *name,
     }
   else
     {
-      each_babl_pixel_format_destroy (babl, NULL);
+      each_babl_format_destroy (babl, NULL);
       return NULL;
     }
 }
 
-BABL_CLASS_TEMPLATE (babl_pixel_format)
+BABL_CLASS_TEMPLATE (babl_format)
index b43d9c46dfae793d5cbfe9d5e74bcca6bf81585b..2a5f879db639a3dc4a5d63df3ba4852a35a69d97 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-#ifndef _BABL_PIXEL_FORMAT_H
-#define _BABL_PIXEL_FORMAT_H
+#ifndef _BABL_FORMAT_H
+#define _BABL_FORMAT_H
 
 #include "babl-classes.h"
-BABL_DEFINE_CLASS (babl_pixel_format)
+BABL_DEFINE_CLASS (babl_format)
 
 #endif
index 4a882eb5f2c82473869f600798e60c8f76d06de9..4de9d8942499e6107d48d8a47d3a1c2aa44c5617 100644 (file)
@@ -29,7 +29,33 @@ enum {
   BABL_DOUBLE,
   BABL_HALF_FLOAT,
 
-  BABL_COMPONENT_BASE = 1000,
+  BABL_U8_LUMA,
+  BABL_U8_CHROMA,
+  BABL_U16_CIE_L,
+  BABL_U16_CIE_AB,
+  BABL_U8_CIE_L,
+  BABL_U8_CIE_AB,
+
+  BABL_MODEL_BASE = 1000,
+  BABL_RGB,
+  BABL_RGBA,
+  BABL_RGB_GAMMA_2_2,
+  BABL_RGBA_GAMMA_2_2,
+  BABL_RGBA_PREMULTIPLIED,
+  BABL_GRAY,
+  BABL_GRAY_ALPHA,
+  BABL_GRAY_GAMMA_2_2,
+  BABL_GRAY_GAMMA_2_2_ALPHA,
+  BABL_GRAY_ALPHA_PREMULTIPLIED,
+  BABL_YCBCR,
+  BABL_YCBCR_ALPHA,
+  BABL_CIE_LAB,
+  BABL_CIE_LAB_ALPHA,
+  BABL_CMY,
+  BABL_CMYK,
+  BABL_CMYK_ALPHA,
+
+  BABL_COMPONENT_BASE = 10000,
   BABL_RED,
   BABL_GREEN,
   BABL_BLUE,
@@ -46,9 +72,9 @@ enum {
   BABL_X,
   BABL_Y,
   BABL_Z,
-  BABL_LAB_L,
-  BABL_LAB_A,
-  BABL_LAB_B,
+  BABL_CIE_L,
+  BABL_CIE_A,
+  BABL_CIE_B,
   BABL_CB,
   BABL_CR,
   BABL_CYAN,
@@ -58,40 +84,24 @@ enum {
   BABL_Z_BUFFER,
   BABL_PADDING,
 
-  BABL_MODEL_BASE = 10000,
-  BABL_RGB,
-  BABL_RGBA,
-  BABL_RGB_GAMMA_2_2,
-  BABL_RGBA_GAMMA_2_2,
-  BABL_RGBA_PREMULTIPLIED,
-  BABL_GRAY,
-  BABL_GRAY_ALPHA,
-  BABL_GRAY_GAMMA_2_2,
-  BABL_GRAY_GAMMA_2_2_ALPHA,
-  BABL_GRAY_ALPHA_PREMULTIPLIED,
-  BABL_YCBCR,
-  BABL_YCBCR_ALPHA,
-  BABL_LAB,
-  BABL_LAB_ALPHA,
-  BABL_CMY,
-  BABL_CMYK,
-  BABL_CMYK_ALPHA,
 
-  BABL_PIXEL_FORMAT_BASE = 100000,
+  BABL_FORMAT_BASE = 100000,
   BABL_SRGB,
   BABL_SRGBA,
   BABL_RGB_FLOAT,
   BABL_RGBA_FLOAT,
   BABL_RGBA_DOUBLE,
   BABL_LAB_FLOAT,
-  BABL_YUV420,
+  BABL_LAB_U16,
+  BABL_LAB_U8,
   BABL_RGB_U8,
   BABL_RGBA_U8,
   BABL_RGBA_U16,
   BABL_CMYK_FLOAT,
   BABL_CMYK_ALPHA_FLOAT,
-  BABL_YUV411,
-  BABL_YUV422,
+  BABL_YCBCR411,
+  BABL_YCBCR422,
+  BABL_YCBCR420,
 
   BABL_PIXEL_USER_BASE,
 };
index 831925c9e748fb91c1e1cdc4249507ddacda516d..d80bc7fcca2e052a363870f2d0f90627fee4d9fb 100644 (file)
@@ -85,23 +85,23 @@ babl_image_new_from_linear (void  *buffer,
   int            calc_pitch=0;
 
   assert (format);
-  assert (format->class_type == BABL_PIXEL_FORMAT ||
+  assert (format->class_type == BABL_FORMAT ||
           format->class_type == BABL_MODEL);
  
   switch (format->class_type)
     {
-      case BABL_PIXEL_FORMAT:
-        for (band=0; band < format->pixel_format.bands; band++)
+      case BABL_FORMAT:
+        for (band=0; band < format->format.bands; band++)
           {
-            BablType *type = format->pixel_format.type[band];
+            BablType *type = format->format.type[band];
             calc_pitch += (type->bits / 8);
           }
 
-        for (band=0; band < format->pixel_format.bands; band++)
+        for (band=0; band < format->format.bands; band++)
           {
-            BablType *type = format->pixel_format.type[band];
+            BablType *type = format->format.type[band];
 
-            component[band] = format->pixel_format.component[band];
+            component[band] = format->format.component[band];
             data[band]      = buffer + offset;
             pitch[band]     = calc_pitch;
             stride[band]    = 0;
@@ -172,9 +172,10 @@ babl_image_new (void *first,
         }
       else
         {
-          new_component = (BablComponent*)babl_component (arg);
+          new_component = (BablComponent*) babl_component (arg);
         }
 
+      /* FIXME: add error checking */
       component [bands] = new_component;
       data      [bands] = va_arg (varg, void*);
       pitch     [bands] = va_arg (varg, int);
@@ -183,7 +184,7 @@ babl_image_new (void *first,
                 
       if (bands>=BABL_MAX_BANDS)
         {
-          babl_log ("%s(): maximum number of bands (%i) exceeded for BablImage",
+          babl_log ("%s(): maximum number of bands (%i) exceeded",
                     __FUNCTION__, BABL_MAX_BANDS);
         }
 
index 611575034db6d03260b17c34ca35d0f57a92fed8..c3666f89b67f4646e5532f7883fb6c38189624f2 100644 (file)
@@ -30,7 +30,7 @@
 Babl * babl_image_new             (void *first_component,
                                    ...);
 
-/* create a new BablImage based on a packed BablPixelFormat (or BablModel which
+/* create a new BablImage based on a packed BablFormat (or BablModel which
  * is a virtual pixelformat based on the BablModel using only doubles in the
  * order they are listed in the model.
  */
index 8f2376d3e6f488b51eaf3560dd276d0bf88af8b7..479ac68aed1dc6cdace06c9e3e4dbcaa5b0b1f4a 100644 (file)
@@ -28,13 +28,13 @@ static const char *class_names[] =
     "BablSampling",
     "BablComponent",
     "BablModel",
-    "BablPixelFormat",
+    "BablFormat",
     "BablConversion",
     "BablConversionType",
     "BablConversionTypePlanar",
     "BablConversionModelPlanar",
-    "BablConversionPixelFormat",
-    "BablConversionPixelFormatPlanar",
+    "BablConversionFormat",
+    "BablConversionFormatPlanar",
     "BablFish",
     "BablFishReference",
     "BablImage",
index 8607497b1ec74750c8367c1a3b7a0b3882ee5567..b5e3fc540e2bdce31444d51bab39bae6dfeb140d 100644 (file)
@@ -55,7 +55,7 @@ type_name##_id (int id)                                       \
   babl = db_exist (id, NULL);                                 \
   if (!babl)                                                  \
     {                                                         \
-      babl_log ("%s(\"%i\"): not found", __FUNCTION__, id);   \
+      babl_log ("%s(%i): not found", __FUNCTION__, id);   \
     }                                                         \
   return babl;                                                \
 }
index 001a41d71fc7422a9bd8690ac74c0cb0d8f02cb3..b20bd86e8b7022a416f5d03e77e0d342ae9acfbc 100644 (file)
@@ -23,7 +23,7 @@
 static void sampling_introspect     (Babl *babl);
 static void model_introspect        (Babl *babl);
 static void type_introspect         (Babl *babl);
-static void pixel_format_introspect (Babl *babl);
+static void format_introspect       (Babl *babl);
 static int  each_introspect         (Babl *babl,
                                      void *user_data);
 
@@ -47,7 +47,7 @@ babl_introspect (void)
   babl_model_each        (each_introspect, NULL);
   babl_log ("%s","");
   babl_log ("Pixel formats:%s", "");
-  babl_pixel_format_each (each_introspect, NULL);
+  babl_format_each (each_introspect, NULL);
   babl_log ("%s","");
   babl_log ("conversions:%s", "");
   babl_conversion_each   (each_introspect, NULL);
@@ -135,18 +135,18 @@ sampling_introspect (Babl *babl)
 
 
 static void
-pixel_format_introspect (Babl *babl)
+format_introspect (Babl *babl)
 {
   int i;
-  babl_log ("\t\tplanar=%i", babl->pixel_format.planar);
-  babl_log ("\t\tbands=%i",  babl->pixel_format.bands);
+  babl_log ("\t\tplanar=%i", babl->format.planar);
+  babl_log ("\t\tbands=%i",  babl->format.bands);
 
-  for (i=0; i< babl->pixel_format.bands; i++)
+  for (i=0; i< babl->format.bands; i++)
     {
       babl_log ("\t\tband[%i] type='%s' component='%s' sampling='%s'",
-                i,   babl->pixel_format.type[i]->instance.name,
-                     babl->pixel_format.component[i]->instance.name,
-                     babl->pixel_format.sampling[i]->instance.name);
+                i,   babl->format.type[i]->instance.name,
+                     babl->format.component[i]->instance.name,
+                     babl->format.sampling[i]->instance.name);
     }
 }
 
@@ -171,8 +171,8 @@ each_introspect (Babl *babl,
         model_introspect (babl);
         item_conversions_introspect (babl);
         break;
-      case BABL_PIXEL_FORMAT:
-        pixel_format_introspect (babl);
+      case BABL_FORMAT:
+        format_introspect (babl);
         item_conversions_introspect (babl);
         break;
       case BABL_SAMPLING:
index 6b44cd7f88217693375a72fa476046e2afd6ed95..2338b0c8fe94ff6c559d21c57752b3b4e8ee41e1 100644 (file)
@@ -108,15 +108,15 @@ babl_model_new (const char *name,
               case BABL_TYPE:
               case BABL_SAMPLING:
               case BABL_INSTANCE:
-              case BABL_PIXEL_FORMAT:
+              case BABL_FORMAT:
 
 
               case BABL_CONVERSION:
               case BABL_CONVERSION_TYPE:
               case BABL_CONVERSION_TYPE_PLANAR:
               case BABL_CONVERSION_MODEL_PLANAR:
-              case BABL_CONVERSION_PIXEL_FORMAT:
-              case BABL_CONVERSION_PIXEL_FORMAT_PLANAR:
+              case BABL_CONVERSION_FORMAT:
+              case BABL_CONVERSION_FORMAT_PLANAR:
               case BABL_FISH:
               case BABL_FISH_REFERENCE:
               case BABL_IMAGE:
index d31cbe5c019d0bfa1105fa8527b10c503102296e..12df09bd9d56f441a9e73ec37e6576f0e068ac5f 100644 (file)
@@ -17,8 +17,8 @@
  * Boston, MA 02111-1307, USA.
  */
 
-#ifndef _BABL_pixel_format_H
-#define _BABL_pixel_format_H
+#ifndef _BABL_format_H
+#define _BABL_format_H
 
 #include "babl-classes.h"
 BABL_DEFINE_CLASS (babl_model)
index d10fb5a95ec22c9359a7ec613fb0db0f3cdfe653..1619a817974734807bce885b26aea7cbbba6d6a5 100644 (file)
 #define BABL_MAX_BANDS 32
 
 static int 
-each_babl_pixel_format_destroy (Babl *babl,
+each_babl_format_destroy (Babl *babl,
                                 void *data)
 {
-  babl_free (babl->pixel_format.from);
-  babl_free (babl->pixel_format.to);
+  babl_free (babl->format.from);
+  babl_free (babl->format.to);
   babl_free (babl);
 
   return 0;  /* continue iterating */
 }
 
 static Babl *
-pixel_format_new (const char     *name,
+format_new (const char     *name,
                   int             id,
                   int             planar,
                   int             bands,
@@ -53,7 +53,7 @@ pixel_format_new (const char     *name,
   int              band;
 
   /* allocate all memory in one chunk */
-  babl  = babl_calloc (sizeof (BablPixelFormat) +
+  babl  = babl_calloc (sizeof (BablFormat) +
                        strlen (name) + 1 +
                        sizeof (BablComponent*) * (bands+1) +
                        sizeof (BablSampling*)  * (bands+1) +
@@ -61,34 +61,34 @@ pixel_format_new (const char     *name,
                        sizeof (int)            * (bands+1) +
                        sizeof (int)            * (bands+1),1);
 
-  babl->pixel_format.component = ((void *)babl) + sizeof (BablPixelFormat);
-  babl->pixel_format.type      = ((void *)babl->pixel_format.component) + sizeof (BablComponent*) * (bands+1);
-  babl->pixel_format.sampling  = ((void *)babl->pixel_format.type)      + sizeof (BablType*) * (bands+1);
-  babl->instance.name          = ((void *)babl->pixel_format.sampling)  + sizeof (BablSampling*) * (bands+1);
+  babl->format.component = ((void *)babl) + sizeof (BablFormat);
+  babl->format.type      = ((void *)babl->format.component) + sizeof (BablComponent*) * (bands+1);
+  babl->format.sampling  = ((void *)babl->format.type)      + sizeof (BablType*) * (bands+1);
+  babl->instance.name          = ((void *)babl->format.sampling)  + sizeof (BablSampling*) * (bands+1);
   
-  babl->class_type    = BABL_PIXEL_FORMAT;
+  babl->class_type    = BABL_FORMAT;
   babl->instance.id   = id;
   strcpy (babl->instance.name, name);
 
-  babl->pixel_format.model  = model;
-  babl->pixel_format.bands  = bands;
-  babl->pixel_format.planar = planar;
+  babl->format.model  = model;
+  babl->format.bands  = bands;
+  babl->format.planar = planar;
 
   for (band=0; band < bands; band++)
     {
-      babl->pixel_format.component[band] = component[band];
-      babl->pixel_format.type[band] = type[band];
-      babl->pixel_format.sampling[band] = sampling[band];
+      babl->format.component[band] = component[band];
+      babl->format.type[band] = type[band];
+      babl->format.sampling[band] = sampling[band];
     }
-  babl->pixel_format.component[band] = NULL;
-  babl->pixel_format.type[band]      = NULL;
-  babl->pixel_format.sampling[band]  = NULL;
+  babl->format.component[band] = NULL;
+  babl->format.type[band]      = NULL;
+  babl->format.sampling[band]  = NULL;
 
   return babl;
 }
 
 Babl *
-babl_pixel_format_new (const char *name,
+babl_format_new (const char *name,
                        ...)
 {
   va_list varg;
@@ -153,13 +153,13 @@ babl_pixel_format_new (const char *name,
                   model = (BablModel*)arg;
                   break;
               case BABL_INSTANCE:
-              case BABL_PIXEL_FORMAT:
+              case BABL_FORMAT:
               case BABL_CONVERSION:
               case BABL_CONVERSION_TYPE:
               case BABL_CONVERSION_TYPE_PLANAR:
               case BABL_CONVERSION_MODEL_PLANAR:
-              case BABL_CONVERSION_PIXEL_FORMAT:
-              case BABL_CONVERSION_PIXEL_FORMAT_PLANAR:
+              case BABL_CONVERSION_FORMAT:
+              case BABL_CONVERSION_FORMAT_PLANAR:
               case BABL_FISH:
               case BABL_FISH_REFERENCE:
               case BABL_IMAGE:
@@ -188,7 +188,7 @@ babl_pixel_format_new (const char *name,
       
       else
         {
-          babl_log ("%s: unhandled parameter '%s' for pixel_format '%s'",
+          babl_log ("%s: unhandled parameter '%s' for format '%s'",
                     __FUNCTION__, arg, name);
           exit (-1);
         }
@@ -197,7 +197,7 @@ babl_pixel_format_new (const char *name,
   va_end   (varg);
 
 
-  babl = pixel_format_new (name, id,
+  babl = format_new (name, id,
                            planar, bands, model,
                            component, sampling, type);
 
@@ -208,9 +208,9 @@ babl_pixel_format_new (const char *name,
     }
   else
     {
-      each_babl_pixel_format_destroy (babl, NULL);
+      each_babl_format_destroy (babl, NULL);
       return NULL;
     }
 }
 
-BABL_CLASS_TEMPLATE (babl_pixel_format)
+BABL_CLASS_TEMPLATE (babl_format)
index b43d9c46dfae793d5cbfe9d5e74bcca6bf81585b..2a5f879db639a3dc4a5d63df3ba4852a35a69d97 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-#ifndef _BABL_PIXEL_FORMAT_H
-#define _BABL_PIXEL_FORMAT_H
+#ifndef _BABL_FORMAT_H
+#define _BABL_FORMAT_H
 
 #include "babl-classes.h"
-BABL_DEFINE_CLASS (babl_pixel_format)
+BABL_DEFINE_CLASS (babl_format)
 
 #endif
index a861fff75499aab86519ff0478247f8568352f2f..88d9aa24ed919148d89ee63522de42b80d93dd75 100644 (file)
@@ -19,6 +19,8 @@
 
 #include "babl.h"
 #include "babl-internal.h"
+
+static int OK;
  
 static int
 foo (Babl *babl,
@@ -56,8 +58,11 @@ type_sanity (Babl *babl,
         }
     }
   if (!ok)
-    babl_log ("lack of sanity! type '%s' has no conversion to double",
-      babl->instance.name);
+    {
+      OK = 0;
+      babl_log ("lack of sanity! type '%s' has no conversion to double",
+                babl->instance.name);
+    }
 
 
   ok = 0;
@@ -76,8 +81,11 @@ type_sanity (Babl *babl,
         }
     }
   if (!ok)
-    babl_log ("lack of sanity! type '%s' has no conversion from double",
-      babl->instance.name);
+    {
+      OK=0;
+      babl_log ("lack of sanity! type '%s' has no conversion from double",
+                babl->instance.name);
+    }
 
   return 0;
 }
@@ -108,8 +116,11 @@ model_sanity (Babl *babl,
         }
     }
   if (!ok)
-    babl_log ("lack of sanity! model '%s' has no conversion to 'rgba'",
-      babl->instance.name);
+    {
+      OK=0;
+      babl_log ("lack of sanity! model '%s' has no conversion to 'rgba'",
+                babl->instance.name);
+    }
 
 
   ok = 0;
@@ -128,8 +139,11 @@ model_sanity (Babl *babl,
         }
     }
   if (!ok)
-    babl_log ("lack of sanity! model '%s' has no conversion from 'rgba'",
-      babl->instance.name);
+    {
+      babl_log ("lack of sanity! model '%s' has no conversion from 'rgba'",
+                babl->instance.name);
+      OK=0;
+    }
 
   return 0;
 }
@@ -140,29 +154,31 @@ id_sanity (Babl *babl,
 {
   if (0 == babl->instance.id)
     {
+      OK=0;
       babl_log ("%s\t'%s' has id==0",
         babl_class_name (babl->class_type), babl->instance.name);
     }
   return 0;
 }
 
-void
+int
 babl_sanity (void)
 {
+  OK=1;
+  
   babl_type_each         (id_sanity, NULL);
   babl_component_each    (id_sanity, NULL);
   babl_model_each        (id_sanity, NULL);
-  babl_pixel_format_each (id_sanity, NULL);
+  babl_format_each       (id_sanity, NULL);
 
   babl_type_each         (type_sanity, NULL);
   babl_sampling_each     (foo, NULL);
   babl_component_each    (foo, NULL);
   babl_model_each        (model_sanity, NULL);
-  babl_pixel_format_each (foo, NULL);
+  babl_format_each       (foo, NULL);
   babl_conversion_each   (foo, NULL);
 
-
-
+  return OK;
 }
 
 static Babl *babl_conversion_source (Babl *babl)
index 0f410673c961cf0aab08531c5e71bad657300a49..18c978ca207d1d38e2b581c75e343665bf9a1071 100644 (file)
@@ -20,6 +20,6 @@
 #ifndef _BABL_SANITY_H
 #define _BABL_SANITY_H
 
-void babl_sanity (void);
+int babl_sanity (void);
 
 #endif
index 0412cfa4dd5c7314c90ab72f131989fab0424a1b..362fe58627734aea4ea403d89af737e9f4ac3eb7 100644 (file)
@@ -62,8 +62,13 @@ babl_type_new (const char *name,
 {
   va_list  varg;
   Babl    *babl;
-  int      id    = 0;
-  int      bits  = 0;
+  int      id         = 0;
+  int      is_integer = 0;
+  int      bits       = 0;
+  long     min        = 0;
+  long     max        = 255;
+  double   min_val    = 0.0;
+  double   max_val    = 0.0;
 
   const char *arg=name;
 
@@ -91,11 +96,33 @@ babl_type_new (const char *name,
       else if (!strcmp (arg, "bits"))
         {
           bits = va_arg (varg, int);
+          min = 0;
+          max = 1<<bits;
+        }
+      else if (!strcmp (arg, "integer"))
+        {
+          is_integer = va_arg (varg, int);
+        }
+      else if (!strcmp (arg, "min"))
+        {
+          min = va_arg (varg, long);
+        }
+      else if (!strcmp (arg, "max"))
+        {
+          max = va_arg (varg, long);
+        }
+      else if (!strcmp (arg, "min_val"))
+        {
+          min_val = va_arg (varg, double);
+        }
+      else if (!strcmp (arg, "max_val"))
+        {
+          max_val = va_arg (varg, double);
         }
       
       else
         {
-          babl_log ("%s(): unhandled parameter '%s' for pixel_format '%s'",
+          babl_log ("%s(): unhandled parameter '%s' for format '%s'",
                     __FUNCTION__, arg, name);
           exit (-1);
         }
index ddbc1bd5fbc0ed65f3e4c010b5e2a60dc2d4e588..c0a83f9ca42d67665e8498d686f9418840c550e2 100644 (file)
@@ -34,7 +34,7 @@ babl_init (void)
       babl_sampling_init ();
       babl_component_init ();
       babl_model_init ();
-      babl_pixel_format_init ();
+      babl_format_init ();
       babl_conversion_init ();
       babl_base_init ();
       babl_sanity ();
@@ -50,7 +50,7 @@ babl_destroy (void)
     {
       babl_fish_destroy ();
       babl_conversion_destroy ();
-      babl_pixel_format_destroy ();
+      babl_format_destroy ();
       babl_model_destroy ();
       babl_component_destroy ();
       babl_sampling_destroy ();
index 4ac555a398665203602cdd9343b7b0cc4db9eec0..900f3edeff4999c2174ed8bbe6de51ea2d6af569 100644 (file)
@@ -39,7 +39,6 @@
 
 
 void babl_init       (void);
-void babl_sanity     (void);
 void babl_introspect (void);
 void babl_destroy    (void);
 
index 4c10122c3a49474ee7df1afd252d7c395fc5cf68..219d6cabf55fc576d20e52615f304eaa9e13b7ac 100644 (file)
@@ -27,7 +27,7 @@
 static void components    (void);
 static void models        (void);
 static void conversions   (void);
-static void pixel_formats (void);
+static void formats       (void);
 
 void
 babl_base_model_cmyk (void)
@@ -35,7 +35,7 @@ babl_base_model_cmyk (void)
   components    ();
   models        ();
   conversions   ();
-  pixel_formats ();
+  formats       ();
 }
 
 static void
@@ -252,7 +252,7 @@ conversions (void)
 }
 
 static void
-pixel_formats (void)
+formats (void)
 {
 }
 
index 5c1dd35c45ee42d6dd2e33472d3695d40717213a..4a6176480c70bb06808616a13024d47ad4deead6 100644 (file)
@@ -51,7 +51,7 @@ components (void)
    NULL);
 
   babl_component_new (
-   "Y-g2.2", 
+   "Y'", 
    "id",    BABL_LUMINANCE_GAMMA_2_2,
    "luma",
    NULL);
@@ -67,13 +67,13 @@ models (void)
     NULL);
 
   babl_model_new (
-    "gray-g2.2",
+    "gray'",
     "id", BABL_GRAY_GAMMA_2_2,
     babl_component_id (BABL_LUMINANCE_GAMMA_2_2),
     NULL);
 
   babl_model_new (
-    "graya-g2.2",
+    "gray'a",
     "id", BABL_GRAY_GAMMA_2_2_ALPHA,
     babl_component_id (BABL_LUMINANCE_GAMMA_2_2),
     babl_component_id (BABL_ALPHA),
@@ -376,7 +376,7 @@ static void
 conversions (void)
 {
   babl_conversion_new (
-    "babl-base: gray-g2.2 to rgba",
+    "babl-base: gray' to rgba",
     "source",      babl_model_id (BABL_GRAY_GAMMA_2_2),
     "destination", babl_model_id (BABL_RGBA),
     "planar",      gray_2_2_to_rgb,
@@ -385,7 +385,7 @@ conversions (void)
 
 
   babl_conversion_new (
-    "babl-base: rgba to gray-g2.2",
+    "babl-base: rgba to gray'",
     "source",      babl_model_id (BABL_RGBA),
     "destination", babl_model_id (BABL_GRAY_GAMMA_2_2),
     "planar",      rgb_to_gray_2_2,
@@ -393,7 +393,7 @@ conversions (void)
   );
 
   babl_conversion_new (
-    "babl-base: graya-g2.2 to rgba",
+    "babl-base: gray'a to rgba",
     "source",      babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA),
     "destination", babl_model_id (BABL_RGBA),
     "planar",      gray_2_2_to_rgb,
@@ -401,7 +401,7 @@ conversions (void)
   );
 
   babl_conversion_new (
-    "babl-base: rgba to graya-g2.2",
+    "babl-base: rgba to gray'a",
     "source",      babl_model_id (BABL_RGBA),
     "destination", babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA),
     "planar",      rgb_to_gray_2_2,
index 0f0729fa92c2d0dcd5507ccd050f54ef211d3ddd..5bebf1316c49d3d940a4f6bc99032bd1e9b5ab6a 100644 (file)
@@ -25,7 +25,7 @@
 static void components    (void);
 static void models        (void);
 static void conversions   (void);
-static void pixel_formats (void);
+static void formats       (void);
 
 void
 babl_base_model_lab (void)
@@ -34,7 +34,7 @@ babl_base_model_lab (void)
   components    ();
   models        ();
   conversions   ();
-  pixel_formats ();
+  formats       ();
 }
 
 static void
@@ -42,19 +42,18 @@ components (void)
 {
   babl_component_new (
    "CIE L",
-   "id",    BABL_LAB_L,
-   "luma",
+   "id",    BABL_CIE_L,
    NULL);
 
   babl_component_new (
    "CIE a",
-   "id",    BABL_LAB_A,
+   "id",    BABL_CIE_A,
    "chroma",
    NULL);
 
   babl_component_new (
    "CIE b",
-   "id",    BABL_LAB_B,
+   "id",    BABL_CIE_B,
    "chroma",
    NULL);
 }
@@ -64,18 +63,18 @@ models (void)
 {
   babl_model_new (
     "CIE Lab",
-    "id", BABL_LAB,
-    babl_component_id (BABL_LAB_L),
-    babl_component_id (BABL_LAB_A),
-    babl_component_id (BABL_LAB_B),
+    "id", BABL_CIE_LAB,
+    babl_component_id (BABL_CIE_L),
+    babl_component_id (BABL_CIE_A),
+    babl_component_id (BABL_CIE_B),
     NULL);
 
   babl_model_new (
     "CIE Lab alpha",
-    "id", BABL_LAB_ALPHA,
-    babl_component_id (BABL_LAB_L),
-    babl_component_id (BABL_LAB_A),
-    babl_component_id (BABL_LAB_B),
+    "id", BABL_CIE_LAB_ALPHA,
+    babl_component_id (BABL_CIE_L),
+    babl_component_id (BABL_CIE_A),
+    babl_component_id (BABL_CIE_B),
     babl_component_id (BABL_ALPHA),
     NULL);
 }
@@ -148,43 +147,43 @@ static void
 conversions (void)
 {
   babl_conversion_new (
-    "babl-base: rgba to lab",
+    "babl-base: rgba to cie-lab",
     "source",      babl_model_id (BABL_RGBA),
-    "destination", babl_model_id (BABL_LAB),
+    "destination", babl_model_id (BABL_CIE_LAB),
     "planar",      rgb_to_lab,
     NULL
   );
   babl_conversion_new (
-    "babl-base: lab to rgba",
-    "source",      babl_model_id (BABL_LAB),
+    "babl-base: cie-lab to rgba",
+    "source",      babl_model_id (BABL_CIE_LAB),
     "destination", babl_model_id (BABL_RGBA),
     "planar",      lab_to_rgb,
     NULL
   );
   babl_conversion_new (
-    "babl-base: rgb to lab",
+    "babl-base: rgb to cie-lab",
     "source",      babl_model_id (BABL_RGB),
-    "destination", babl_model_id (BABL_LAB),
+    "destination", babl_model_id (BABL_CIE_LAB),
     "planar",      rgb_to_lab,
     NULL
   );
   babl_conversion_new (
-    "babl-base: lab to rgb",
-    "source",      babl_model_id (BABL_LAB),
+    "babl-base: cie-lab to rgb",
+    "source",      babl_model_id (BABL_CIE_LAB),
     "destination", babl_model_id (BABL_RGB),
     "planar",      lab_to_rgb,
     NULL
   );
   babl_conversion_new (
-    "babl-base: rgba to laba",
+    "babl-base: rgba to cie-lab-float",
     "source",      babl_model_id (BABL_RGBA),
-    "destination", babl_model_id (BABL_LAB_ALPHA),
+    "destination", babl_model_id (BABL_CIE_LAB_ALPHA),
     "planar",      rgb_to_lab,
     NULL
   );
   babl_conversion_new (
-    "babl-base: laba to rgba",
-    "source",      babl_model_id (BABL_LAB_ALPHA),
+    "babl-base: cie-lab-float to rgba",
+    "source",      babl_model_id (BABL_CIE_LAB_ALPHA),
     "destination", babl_model_id (BABL_RGBA),
     "planar",      lab_to_rgb,
     NULL
@@ -192,15 +191,39 @@ conversions (void)
 }
 
 static void
-pixel_formats (void)
+formats (void)
 {
-  babl_pixel_format_new (
-    "lab-float",
+  babl_format_new (
+    "cie-lab-float",
     "id", BABL_LAB_FLOAT,
-    babl_model_id     (BABL_LAB),
+    babl_model_id     (BABL_CIE_LAB),
     babl_type_id      (BABL_FLOAT),
-    babl_component_id (BABL_LAB_L), 
-    babl_component_id (BABL_LAB_A), 
-    babl_component_id (BABL_LAB_B),
+    babl_component_id (BABL_CIE_L), 
+    babl_component_id (BABL_CIE_A), 
+    babl_component_id (BABL_CIE_B),
+    NULL);
+
+  babl_format_new (
+    "cie-lab-u8",
+    "id", BABL_LAB_U8,
+    babl_model_id     (BABL_CIE_LAB),
+    babl_type_id      (BABL_U8_CIE_L),
+    babl_component_id (BABL_CIE_L),
+    babl_type_id      (BABL_U8_CIE_AB),
+    babl_component_id (BABL_CIE_A), 
+    babl_type_id      (BABL_U8_CIE_AB),
+    babl_component_id (BABL_CIE_B),
+    NULL);
+
+  babl_format_new (
+    "cie-lab-u16",
+    "id", BABL_LAB_U16,
+    babl_model_id     (BABL_CIE_LAB),
+    babl_type_id      (BABL_U16_CIE_L),
+    babl_component_id (BABL_CIE_L),
+    babl_type_id      (BABL_U16_CIE_AB),
+    babl_component_id (BABL_CIE_A), 
+    babl_type_id      (BABL_U16_CIE_AB),
+    babl_component_id (BABL_CIE_B),
     NULL);
 }
index 96d41708e5d24310df821c5944ec9a760a9c5491..23853d44a3f0125b06e0e49a4a323de1dbb441ad 100644 (file)
@@ -24,7 +24,7 @@
 static void models        (void);
 static void components    (void);
 static void conversions   (void);
-static void pixel_formats (void);
+static void formats       (void);
 
 void
 babl_base_model_rgb (void)
@@ -32,7 +32,7 @@ babl_base_model_rgb (void)
   components    ();
   models        ();
   conversions   ();
-  pixel_formats ();
+  formats       ();
 }
 
 static void
@@ -60,21 +60,21 @@ components (void)
    NULL);
 
   babl_component_new (
-    "R-g2.2",
+    "R'",
    "id",    BABL_RED_GAMMA_2_2,
     "luma",
     "chroma",
     NULL);
 
   babl_component_new (
-    "G-g2.2",
+    "G'",
    "id",    BABL_GREEN_GAMMA_2_2,
    "luma", 
    "chroma",
    NULL);
   
   babl_component_new (
-    "B-g2.2",
+    "B'",
    "id",    BABL_BLUE_GAMMA_2_2,
    "luma",
    "chroma",
@@ -141,7 +141,7 @@ models (void)
     NULL);
 
   babl_model_new (
-    "rgb-g2.2",
+    "rgb'",
     "id", BABL_RGB_GAMMA_2_2,
     babl_component_id (BABL_RED_GAMMA_2_2),
     babl_component_id (BABL_GREEN_GAMMA_2_2),
@@ -149,7 +149,7 @@ models (void)
     NULL);
 
   babl_model_new (
-    "rgba-g2.2",
+    "rgb'a",
     "id", BABL_RGBA_GAMMA_2_2,
     babl_component_id (BABL_RED_GAMMA_2_2),
     babl_component_id (BABL_GREEN_GAMMA_2_2),
@@ -230,7 +230,10 @@ g3_inv_gamma_2_2 (int    src_bands,
         }
       for (;band<dst_bands;band++)
         {
-          *(double*)dst[band] = *(double*) src[band];
+          if (band<src_bands)
+            *(double*)dst[band] = *(double*) src[band];
+          else
+            *(double*)dst[band] = 1.0;
         }
       BABL_PLANAR_STEP
     }
@@ -377,9 +380,9 @@ conversions (void)
 }
 
 static void
-pixel_formats (void)
+formats (void)
 {
-    babl_pixel_format_new (
+    babl_format_new (
     "srgb",
     "id", BABL_SRGB,
     babl_model_id     (BABL_RGB_GAMMA_2_2),
@@ -389,7 +392,7 @@ pixel_formats (void)
     babl_component_id (BABL_BLUE_GAMMA_2_2),
     NULL);
 
-  babl_pixel_format_new (
+  babl_format_new (
     "srgba",
     "id", BABL_SRGBA,
     babl_model_id     (BABL_RGBA_GAMMA_2_2),
@@ -400,7 +403,7 @@ pixel_formats (void)
     babl_component_id (BABL_ALPHA),
     NULL);
 
-  babl_pixel_format_new (
+  babl_format_new (
     "rgba-float",
     "id",              BABL_RGBA_FLOAT,
     babl_model_id     (BABL_RGBA),
@@ -411,7 +414,7 @@ pixel_formats (void)
     babl_component_id (BABL_ALPHA),
     NULL);
 
-  babl_pixel_format_new (
+  babl_format_new (
     "rgba-double",
     "id",              BABL_RGBA_DOUBLE,
     babl_model_id     (BABL_RGBA),
@@ -422,7 +425,7 @@ pixel_formats (void)
     babl_component_id (BABL_ALPHA),
     NULL);
 
-  babl_pixel_format_new (
+  babl_format_new (
     "rgb-float",
     "id", BABL_RGB_FLOAT,
     babl_model_id     (BABL_RGB),
index d3c7b242f2333cb5c44c906afb7ee3cf2ea7682d..67431981a61e53decc37a417142a269a960ef667 100644 (file)
@@ -27,7 +27,7 @@
 static void components    (void);
 static void models        (void);
 static void conversions   (void);
-static void pixel_formats (void);
+static void formats (void);
 
 void
 babl_base_model_ycbcr (void)
@@ -35,7 +35,7 @@ babl_base_model_ycbcr (void)
   components    ();
   models        ();
   conversions   ();
-  pixel_formats ();
+  formats       ();
 }
 
 static void
@@ -58,7 +58,7 @@ static void
 models (void)
 {
   babl_model_new (
-    "ycbcr",
+    "y'cbcr",
     "id", BABL_YCBCR,
     babl_component_id (BABL_LUMINANCE_GAMMA_2_2),
     babl_component_id (BABL_CB),
@@ -66,7 +66,7 @@ models (void)
     NULL);
 
   babl_model_new (
-    "ycbcra",
+    "y'cbcra",
     "id", BABL_YCBCR_ALPHA,
     babl_component_id (BABL_LUMINANCE_GAMMA_2_2),
     babl_component_id (BABL_CB),
@@ -155,42 +155,42 @@ static void
 conversions (void)
 {
   babl_conversion_new (
-    "babl-base: rgba to ycbcr",
+    "babl-base: rgba to y'cbcr",
     "source",      babl_model_id (BABL_RGBA),
     "destination", babl_model_id (BABL_YCBCR),
     "planar",      rgb_to_ycbcr,
     NULL
   );
   babl_conversion_new (
-    "babl-base: ycbcr to rgba",
+    "babl-base: y'cbcr to rgba",
     "source",      babl_model_id (BABL_YCBCR),
     "destination", babl_model_id (BABL_RGBA),
     "planar",      ycbcr_to_rgb,
     NULL
   );
   babl_conversion_new (
-    "babl-base: rgb to ycbcr",
+    "babl-base: rgb to y'cbcr",
     "source",      babl_model_id (BABL_RGB),
     "destination", babl_model_id (BABL_YCBCR),
     "planar",      rgb_to_ycbcr,
     NULL
   );
   babl_conversion_new (
-    "babl-base: ycbcr to rgb",
+    "babl-base: y'cbcr to rgb",
     "source",      babl_model_id (BABL_YCBCR),
     "destination", babl_model_id (BABL_RGB),
     "planar",      ycbcr_to_rgb,
     NULL
   );
   babl_conversion_new (
-    "babl-base: rgba to ycbcra",
+    "babl-base: rgba to y'cbcra",
     "source",      babl_model_id (BABL_RGBA),
     "destination", babl_model_id (BABL_YCBCR_ALPHA),
     "planar",      rgb_to_ycbcr,
     NULL
   );
   babl_conversion_new (
-    "babl-base: ycbcra to rgba",
+    "babl-base: y'cbcra to rgba",
     "source",      babl_model_id (BABL_YCBCR_ALPHA),
     "destination", babl_model_id (BABL_RGBA),
     "planar",      ycbcr_to_rgb,
@@ -199,44 +199,51 @@ conversions (void)
 }
 
 static void
-pixel_formats (void)
+formats (void)
 {
-#if 0
-  babl_pixel_format_new (
-    "yuv420",
-    "id",          BABL_YUV420,
+  babl_format_new (
+    "y'cbcr420",
+    "id",          BABL_YCBCR420,
     "planar",
     babl_model_id  (BABL_YCBCR),
-    babl_type_id   (BABL_U8),
-    babl_sampling  (1, 1), babl_component_id (BABL_LUMINANCE),
-    babl_sampling  (2, 2), babl_component_id (BABL_CB), 
-    babl_sampling  (2, 2), babl_component_id (BABL_CR),
+    babl_type_id   (BABL_U8_LUMA),
+    babl_sampling  (1, 1),
+    babl_component_id (BABL_LUMINANCE_GAMMA_2_2),
+    babl_type_id   (BABL_U8_CHROMA),
+    babl_sampling  (2, 2),
+    babl_component_id (BABL_CB), 
+    babl_sampling  (2, 2),
+    babl_component_id (BABL_CR),
     NULL);
   
-  babl_pixel_format_new (
-    "yuv411",
-    "id",          BABL_YUV411,
+
+  babl_format_new (
+    "y'cbcr422",
+    "id",          BABL_YCBCR422,
     "planar",
-    babl_type      ("u8"),
+    babl_model_id  (BABL_YCBCR),
+    babl_type_id   (BABL_U8_LUMA),
     babl_sampling  (1, 1),
-    babl_component ("Y"), 
-    babl_sampling  (4, 1),
+    babl_component_id (BABL_LUMINANCE_GAMMA_2_2),
+    babl_type_id   (BABL_U8_CHROMA),
+    babl_sampling  (2, 1),
     babl_component_id (BABL_CB), 
-    babl_sampling  (4, 1),
+    babl_sampling  (2, 1),
     babl_component_id (BABL_CR),
     NULL);
 
-  babl_pixel_format_new (
-    "yuv422",
-    "id",          BABL_YUV422,
+  babl_format_new (
+    "y'cbcr411",
+    "id",          BABL_YCBCR411,
     "planar",
-    babl_type      ("u8"),
+    babl_model_id  (BABL_YCBCR),
+    babl_type_id   (BABL_U8_LUMA),
     babl_sampling  (1, 1),
-    babl_component ("Y"), 
-    babl_sampling  (2, 1),
+    babl_component_id (BABL_LUMINANCE_GAMMA_2_2),
+    babl_type_id   (BABL_U8_CHROMA),
+    babl_sampling  (4, 1),
     babl_component_id (BABL_CB), 
-    babl_sampling  (2, 1),
+    babl_sampling  (4, 1),
     babl_component_id (BABL_CR),
     NULL);
-#endif
 }
index f1850f020e9435dc29beed08e6f97e5244414bb9..215d60910b5257ac3715c90068062c3ee0c377f4 100644 (file)
 
 #include "babl.h"
 
+
+static inline void
+convert_double_u16_scaled (double         min_val,
+                           double         max_val,
+                           unsigned short min,
+                           unsigned short max,
+                           void          *src,
+                           void          *dst,
+                           int            n)
+{
+  while (n--)
+    {
+      double         dval = *(double *) src;
+      unsigned short u16val;
+
+      if (dval < min_val)
+        u16val = min;
+      else if (dval > max_val)
+        u16val = max;
+      else
+        u16val = (dval-min_val) / (max_val-min_val) * (max-min) + min;
+
+      *(unsigned short *) dst = u16val;
+      dst += 2;
+      src += 8;
+    }
+}
+
+static inline void
+convert_u16_double_scaled (double         min_val,
+                           double         max_val,
+                           unsigned short min,
+                           unsigned short max,
+                           void          *src,
+                           void          *dst,
+                           int            n)
+{
+  while (n--)
+    {
+      int    u16val = *(unsigned short*) src;
+      double dval;
+
+      if (u16val < min)
+        dval = min_val;
+      else if (u16val > max)
+        dval = max_val;
+      else
+        dval  = (u16val-min) / (double)(max-min) * (max_val-min_val) + min_val;
+
+      (*(double *) dst) = dval;
+      dst += 8;
+      src += 1;
+    }
+}
+
+
+
 static void
 convert_double_u16 (void *src,
                     void *dst,
@@ -57,6 +114,24 @@ convert_u16_double (void *src,
     }
 }
 
+
+/* source ICC.1:2004-10 */
+
+static void convert_double_u16_l (void *src, void *dst, int n){
+  convert_double_u16_scaled (0.0, 100.0, 0x00, 0xffff, src, dst, n);
+}
+static void convert_u16_l_double (void *src, void *dst, int n){
+  convert_u16_double_scaled (0.0, 100.0, 0x00, 0xffff, src, dst, n);
+}
+
+static void convert_double_u16_ab (void *src, void *dst, int n){
+  convert_double_u16_scaled (-128.0, 127.0, 0x00, 0xffff, src, dst, n);
+}
+static void convert_u16_ab_double (void *src, void *dst, int n){
+  convert_u16_double_scaled (-128.0, 127.0, 0x00, 0xffff, src, dst, n);
+}
+
+
 void
 babl_base_type_u16 (void)
 {
@@ -66,6 +141,29 @@ babl_base_type_u16 (void)
     "bits", 16,
     NULL);
 
+  babl_type_new (
+    "u16-CIE-L",
+    "id",       BABL_U16_CIE_L,
+    "integer",
+    "unsigned",
+    "bits",        16,
+    "min_val",    0.0,
+    "max_val",  100.0,
+    NULL
+  );
+
+  babl_type_new (
+    "u16-CIE-ab",
+    "id",       BABL_U16_CIE_AB,
+    "integer",
+    "unsigned",
+    "bits",        16,
+    "min_val",  -50.0,
+    "max_val",   50.0,
+    NULL
+  );
+
+
   babl_conversion_new (
     "babl-base: u16 to double",
     "source",      babl_type_id (BABL_U16),
@@ -81,4 +179,35 @@ babl_base_type_u16 (void)
     "linear", convert_double_u16,
     NULL
   );
+
+
+  babl_conversion_new (
+    "babl-base: u16-CIE-L to double",
+    "source",      babl_type_id (BABL_U16_CIE_L),
+    "destination", babl_type_id (BABL_DOUBLE),
+    "linear",      convert_u16_l_double,
+    NULL
+  );
+  babl_conversion_new (
+    "babl-base: double to u16-CIE-L",
+    "source",      babl_type_id (BABL_DOUBLE),
+    "destination", babl_type_id (BABL_U16_CIE_L),
+    "linear",      convert_double_u16_l,
+    NULL
+  );
+
+  babl_conversion_new (
+    "babl-base: u16-CIE-ab to double",
+    "source",      babl_type_id (BABL_U16_CIE_AB),
+    "destination", babl_type_id (BABL_DOUBLE),
+    "linear",      convert_u16_ab_double,
+    NULL
+  );
+  babl_conversion_new (
+    "babl-base: double to u16-CIE-ab",
+    "source",      babl_type_id (BABL_DOUBLE),
+    "destination", babl_type_id (BABL_U16_CIE_AB),
+    "linear",      convert_double_u16_ab,
+    NULL
+  );
 }
index b0d812179d02b99967602f286be5bc96f5ff94d2..03a68304f4fb212236a37697f589b1802e09f52f 100644 (file)
 
 #include "babl.h"
 
-static void
-convert_u8_double (void *src,
-                   void *dst,
-                   int   n)
+static inline void
+convert_double_u8_scaled (double        min_val,
+                          double        max_val,
+                          unsigned char min,
+                          unsigned char max,
+                          void         *src,
+                          void         *dst,
+                          int           n)
 {
   while (n--)
     {
-      (*(double *) dst) = (*(unsigned char *) src/255.0);
-      dst += 8;
-      src += 1;
+      double         dval = *(double *) src;
+      unsigned char u8val;
+
+      if (dval < min_val)
+        u8val = min;
+      else if (dval > max_val)
+        u8val = max;
+      else
+        u8val = (dval-min_val) / (max_val-min_val) * (max-min) + min;
+
+      *(unsigned char *) dst = u8val;
+      dst += 1;
+      src += 8;
     }
 }
 
-static void
-convert_double_u8 (void *src,
-                   void *dst,
-                   int   n)
+static inline void
+convert_u8_double_scaled (double        min_val,
+                          double        max_val,
+                          unsigned char min,
+                          unsigned char max,
+                          void         *src,
+                          void         *dst,
+                          int           n)
 {
   while (n--)
     {
-      double         dval = *(double *) src;
-      unsigned char u8val;
+      int    u8val = *(unsigned char *) src;
+      double dval;
 
-      if (dval < 0)
-        u8val = 0;
-      else if (dval > 1)
-        u8val = 255;
+      if (u8val < min)
+        dval = min_val;
+      else if (u8val > max)
+        dval = max_val;
       else
-        u8val = dval*255.0;
+        dval  = (u8val-min) / (double)(max-min) * (max_val-min_val) + min_val;
 
-      *(unsigned char *) dst = u8val;
-      dst += 1;
-      src += 8;
+      (*(double *) dst) = dval;
+      dst += 8;
+      src += 1;
     }
 }
 
+
+static void convert_u8_double (void *src, void *dst, int n){
+  convert_u8_double_scaled (0.0, 1.0, 0, 255, src, dst, n);
+}
+static void convert_double_u8 (void *src, void *dst, int n){
+  convert_double_u8_scaled (0.0, 1.0, 0, 255, src, dst, n);
+}
+
+static void convert_double_u8_luma (void *src, void *dst, int n){
+  convert_double_u8_scaled (0.0, 1.0, 16, 235, src, dst, n);
+}
+static void convert_u8_luma_double (void *src, void *dst, int n){
+  convert_u8_double_scaled (0.0, 1.0, 16, 235, src, dst, n);
+}
+
+static void convert_double_u8_chroma (void *src, void *dst, int n){
+  convert_double_u8_scaled (-0.5, 0.5, 16, 240, src, dst, n);
+}
+static void convert_u8_chroma_double (void *src, void *dst, int n){
+  convert_u8_double_scaled (-0.5, 0.5, 16, 240, src, dst, n);
+}
+
+/* source ICC.1:2004-10 */
+
+static void convert_double_u8_l (void *src, void *dst, int n){
+  convert_double_u8_scaled (0.0, 100.0, 0x00, 0xff, src, dst, n);
+}
+static void convert_u8_l_double (void *src, void *dst, int n){
+  convert_u8_double_scaled (0.0, 100.0, 0x00, 0xff, src, dst, n);
+}
+
+static void convert_double_u8_ab (void *src, void *dst, int n){
+  convert_double_u8_scaled (-128.0, 127.0, 0x00, 0xff, src, dst, n);
+}
+static void convert_u8_ab_double (void *src, void *dst, int n){
+  convert_u8_double_scaled (-128.0, 127.0, 0x00, 0xff, src, dst, n);
+}
+
+
 void
 babl_base_type_u8 (void)
 {
@@ -67,19 +124,121 @@ babl_base_type_u8 (void)
     "bits", 8,
     NULL);
 
+  babl_type_new (
+    "u8-luma",
+    "id",             BABL_U8_LUMA,
+    "bits",           8,
+    NULL
+  );
+
+  babl_type_new (
+    "u8-chroma",
+    "id",             BABL_U8_CHROMA,
+    "integer",
+    "unsigned",
+    "bits",           8,
+    "min",    (long) 16,
+    "max",    (long)240,
+    "min_val",     -0.5,
+    "max_val",      0.5,
+    NULL
+  );
+
+  babl_type_new (
+    "u8-CIE-L",
+    "id",       BABL_U8_CIE_L,
+    "integer",
+    "unsigned",
+    "bits",         8,
+    "min_val",    0.0,
+    "max_val",  100.0,
+    NULL
+  );
+
+  babl_type_new (
+    "u8-CIE-ab",
+    "id",       BABL_U8_CIE_AB,
+    "integer",
+    "unsigned",
+    "bits",         8,
+    "min_val",  -50.0,
+    "max_val",   50.0,
+    NULL
+  );
+
   babl_conversion_new (
     "babl-base: u8 to double",
     "source",      babl_type_id (BABL_U8),
     "destination", babl_type_id (BABL_DOUBLE),
-    "linear", convert_u8_double,
+    "linear",      convert_u8_double,
     NULL
   );
-
   babl_conversion_new (
     "babl-base: double to u8",
     "source",      babl_type_id (BABL_DOUBLE),
     "destination", babl_type_id (BABL_U8),
-    "linear", convert_double_u8,
+    "linear",      convert_double_u8,
+    NULL
+  );
+
+
+  babl_conversion_new (
+    "babl-base: u8-luma to double",
+    "source",      babl_type_id (BABL_U8_LUMA),
+    "destination", babl_type_id (BABL_DOUBLE),
+    "linear",      convert_u8_luma_double,
+    NULL
+  );
+  babl_conversion_new (
+    "babl-base: double to u8-luma",
+    "source",      babl_type_id (BABL_DOUBLE),
+    "destination", babl_type_id (BABL_U8_LUMA),
+    "linear",      convert_double_u8_luma,
+    NULL
+  );
+
+  babl_conversion_new (
+    "babl-base: u8-chroma to double",
+    "source",      babl_type_id (BABL_U8_CHROMA),
+    "destination", babl_type_id (BABL_DOUBLE),
+    "linear",      convert_u8_chroma_double,
+    NULL
+  );
+  babl_conversion_new (
+    "babl-base: double to u8-chroma",
+    "source",      babl_type_id (BABL_DOUBLE),
+    "destination", babl_type_id (BABL_U8_CHROMA),
+    "linear",      convert_double_u8_chroma,
+    NULL
+  );
+
+  babl_conversion_new (
+    "babl-base: u8-CIE-L to double",
+    "source",      babl_type_id (BABL_U8_CIE_L),
+    "destination", babl_type_id (BABL_DOUBLE),
+    "linear",      convert_u8_l_double,
+    NULL
+  );
+  babl_conversion_new (
+    "babl-base: double to u8-CIE-L",
+    "source",      babl_type_id (BABL_DOUBLE),
+    "destination", babl_type_id (BABL_U8_CIE_L),
+    "linear",      convert_double_u8_l,
+    NULL
+  );
+
+  babl_conversion_new (
+    "babl-base: u8-CIE-ab to double",
+    "source",      babl_type_id (BABL_U8_CIE_AB),
+    "destination", babl_type_id (BABL_DOUBLE),
+    "linear",      convert_u8_ab_double,
+    NULL
+  );
+  babl_conversion_new (
+    "babl-base: double to u8-CIE-ab",
+    "source",      babl_type_id (BABL_DOUBLE),
+    "destination", babl_type_id (BABL_U8_CIE_AB),
+    "linear",      convert_double_u8_ab,
     NULL
   );
 }
index 1bc9955d9c39855a40096b1bf378da7afe604b04..8d9c370198f03fb214ac6068a46b0160d8ef7d2c 100644 (file)
@@ -5,15 +5,19 @@ TESTS =                               \
        rgb_to_lab_to_rgb       \
        rgb_to_ycbcr            \
        rgb_to_ycbcr_to_rgb     \
+       srgb_to_lab_u8          \
+       sanity                  \
        babl_class_name
 
 float_to_u8_SOURCES         = float_to_u8.c
 u8_to_float_SOURCES         = u8_to_float.c
 grayscale_to_rgb_SOURCES    = grayscale_to_rgb.c
 rgb_to_lab_to_rgb_SOURCES   = rgb_to_lab_to_rgb.c
+srgb_to_lab_u8_SOURCES      = srgb_to_lab_u8.c
 rgb_to_ycbcr_SOURCES        = rgb_to_ycbcr.c
 rgb_to_ycbcr_to_rgb_SOURCES = rgb_to_ycbcr_to_rgb.c
 babl_class_name_SOURCES     = babl_class_name.c
+sanity_SOURCES              = sanity.c
 
 
 AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/babl
index 573d11399fef7c1a7c578970c75188e80429b54e..fbf13f15fcefd4f1cd782522fe631f6b0d29030f 100644 (file)
@@ -22,7 +22,7 @@
 
 static void model_html              (Babl *babl);
 static void type_html               (Babl *babl);
-static void pixel_format_html       (Babl *babl);
+static void format_html             (Babl *babl);
 
 static int  each_item               (Babl *babl,
                                      void *user_data);
@@ -41,7 +41,7 @@ main (void)
   babl_model_each (each_item, NULL);
   printf ("<tr><td><a name='Pixel-formats'></a>&nbsp;</td></tr>\n");
   printf ("<tr><th>Pixel format</th><th>bytes/pixel</th><th>color model</th><th>bands</th> </tr>\n");
-  babl_pixel_format_each (each_item, NULL);
+  babl_format_each (each_item, NULL);
   printf ("</table>\n");
 
   babl_destroy ();
@@ -63,8 +63,8 @@ each_item (Babl *babl,
       case BABL_MODEL:
         model_html (babl);
         break;
-      case BABL_PIXEL_FORMAT:
-        pixel_format_html (babl);
+      case BABL_FORMAT:
+        format_html (babl);
         break;
       default:
         break;
@@ -95,42 +95,42 @@ type_html (Babl *babl)
 }
 
 static void
-pixel_format_html (Babl *babl)
+format_html (Babl *babl)
 {
   int i;
 
   printf ("<td valign='top'>");
     {
       int bytes=0;
-      for (i=0; i< babl->pixel_format.bands; i++)
+      for (i=0; i< babl->format.bands; i++)
       {
-        bytes += BABL(babl->pixel_format.type[i])->type.bits/8;
+        bytes += BABL(babl->format.type[i])->type.bits/8;
       }
       printf ("<span class='name'>%i</span>", bytes);
     }
   printf ("</td>");
   printf ("<td valign='top'>");
-  printf ("<span class='name'>%s</span>", BABL(babl->pixel_format.model)->instance.name  );
+  printf ("<span class='name'>%s</span>", BABL(babl->format.model)->instance.name  );
   printf ("</td>");
   printf ("<td>");
-  for (i=0; i< babl->pixel_format.bands; i++)
+  for (i=0; i< babl->format.bands; i++)
     {
       printf ("<span class='type'>%s </span><span class='component'>%s</span><span class='spacer'>&nbsp;</span><br/>",
-       BABL(babl->pixel_format.type[i])->instance.name,
-       BABL(babl->pixel_format.component[i])->instance.name  );
+       BABL(babl->format.type[i])->instance.name,
+       BABL(babl->format.component[i])->instance.name  );
     }
   printf ("</td>");
 #if 0
   int i;
-  babl_log ("\t\tplanar=%i", babl->pixel_format.planar);
-  babl_log ("\t\tbands=%i",  babl->pixel_format.bands);
+  babl_log ("\t\tplanar=%i", babl->format.planar);
+  babl_log ("\t\tbands=%i",  babl->format.bands);
 
-  for (i=0; i< babl->pixel_format.bands; i++)
+  for (i=0; i< babl->format.bands; i++)
     {
       babl_log ("\t\tband[%i] type='%s' component='%s' sampling='%s'",
-                i,   babl->pixel_format.type[i]->instance.name,
-                     babl->pixel_format.component[i]->instance.name,
-                     babl->pixel_format.sampling[i]->instance.name);
+                i,   babl->format.type[i]->instance.name,
+                     babl->format.component[i]->instance.name,
+                     babl->format.sampling[i]->instance.name);
     }
 #endif
 }
index 643848b386f47f32e72d2396548fc6cb29f601c3..d411518e4bcecba3a6c24fb380115a787c5bc162 100644 (file)
@@ -32,13 +32,13 @@ struct
     {BABL_SAMPLING,                       "BablSampling"},
     {BABL_COMPONENT,                      "BablComponent"},
     {BABL_MODEL,                          "BablModel"},
-    {BABL_PIXEL_FORMAT,                   "BablPixelFormat"},
+    {BABL_FORMAT,                         "BablFormat"},
     {BABL_CONVERSION,                     "BablConversion"},
     {BABL_CONVERSION_TYPE,                "BablConversionType"},
     {BABL_CONVERSION_TYPE_PLANAR,         "BablConversionTypePlanar"},
     {BABL_CONVERSION_MODEL_PLANAR,        "BablConversionModelPlanar"},
-    {BABL_CONVERSION_PIXEL_FORMAT,        "BablConversionPixelFormat"},
-    {BABL_CONVERSION_PIXEL_FORMAT_PLANAR, "BablConversionPixelFormatPlanar"},
+    {BABL_CONVERSION_FORMAT,              "BablConversionFormat"},
+    {BABL_CONVERSION_FORMAT_PLANAR,       "BablConversionFormatPlanar"},
     {BABL_FISH,                           "BablFish"},
     {BABL_FISH_REFERENCE,                 "BablFishReference"},
     {BABL_IMAGE,                          "BablImage"},
index e1b4bd524d06f679047287152d876522649e06f7..29844c2f00128127fc990c2c67f6ba5bf714ef4d 100644 (file)
@@ -52,14 +52,14 @@ test_float_to_rgb_u8 (void)
 
   
   fish = babl_fish (
-    babl_pixel_format_new (
+    babl_format_new (
       "foo",
       babl_model ("gray"),
       babl_type ("float"),
       babl_component ("Y"),
       NULL
     ),
-    babl_pixel_format_new (
+    babl_format_new (
       "bar",
       babl_model ("gray"),
       babl_type ("u8"),
@@ -67,7 +67,7 @@ test_float_to_rgb_u8 (void)
       NULL
     ));
 
-  babl_fish_process (fish, 
+  babl_process (fish, 
      float_buf, u8_buf, 
      BUFFER_LENGTH);
   
index 6d5170126058ca7daea80085a5b6a8a2d22d39ac..9e9df64337b84309848ce0934225fe39113e69a5 100644 (file)
@@ -38,14 +38,14 @@ test (void)
 
   
   fish = babl_fish (
-    babl_pixel_format_new (
+    babl_format_new (
       "foo",
       babl_model ("gray"),
       babl_type ("float"),
       babl_component ("Y"),
       NULL
     ),
-    babl_pixel_format_new (
+    babl_format_new (
       "bar",
       babl_model ("rgb"),
       babl_type ("float"),
@@ -56,7 +56,7 @@ test (void)
     )
   );
 
-  babl_fish_process (fish, 
+  babl_process (fish, 
      grayscale_buf, rgb_buf, 
      PIXELS);
   
index 9c5f4776641f39fd34eac68bbc7c91caa1a607a0..439465112cff6d2400551c877eff948773c6e71b 100644 (file)
@@ -75,7 +75,7 @@ test (void)
 
   
   fish = babl_fish (
-    babl_pixel_format_new (
+    babl_format_new (
       "foo",
       babl_model ("rgb"),
       babl_type ("float"),
@@ -84,7 +84,7 @@ test (void)
       babl_component ("B"),
       NULL
     ),
-    babl_pixel_format_new (
+    babl_format_new (
       "bar",
       babl_model ("CIE Lab"),
       babl_type ("float"), 
@@ -95,12 +95,14 @@ test (void)
     )
   );
 
-  babl_fish_process (fish, source_buf, temp_buf, PIXELS);
+  babl_process (fish, source_buf, temp_buf, PIXELS);
 
-  fish = babl_fish (babl_pixel_format ("bar"),
-                    babl_pixel_format ("foo"));
+  /* this test tests both pixel format creation, and the scope of
+   * babl_fish()'s polymorphism
+   */
+  fish = babl_fish ("bar","foo");
   
-  babl_fish_process (fish, temp_buf, destination_buf, PIXELS);
+  babl_process (fish, temp_buf, destination_buf, PIXELS);
 
   for (i=0; i<PIXELS * 3; i++)
     {
index 11d03e77d307ff3266761df3ebb9bae2e4200c32..3abdaa1274ddaac6780ef682464ff14b689ab07d 100644 (file)
@@ -52,7 +52,7 @@ test (void)
   int   OK=1;
   
   fish = babl_fish (
-    babl_pixel_format_new (
+    babl_format_new (
       "foo",
       babl_model ("rgb"),
       babl_type ("float"),
@@ -61,9 +61,9 @@ test (void)
       babl_component ("B"),
       NULL
     ),
-    babl_pixel_format_new (
+    babl_format_new (
       "bar",
-      babl_model ("ycbcr"),
+      babl_model ("y'cbcr"),
       babl_type ("float"),
       babl_component ("Y"),
       babl_component ("Cb"),
@@ -72,7 +72,7 @@ test (void)
     )
   );
 
-  babl_fish_process (fish, source_buf, destination_buf, PIXELS);
+  babl_process (fish, source_buf, destination_buf, PIXELS);
   
   for (i=0; i<PIXELS * 3; i++)
     {
index 57ee6e807342d49eb860c32d8120b52eb028353f..ac23e4dfc850b6e65a5087c4b881e80697344653 100644 (file)
@@ -44,7 +44,7 @@ test (void)
   int   OK=1;
   
   fish = babl_fish (
-    babl_pixel_format_new (
+    babl_format_new (
       "foo",
       babl_model ("rgb"),
       babl_type ("float"),
@@ -53,9 +53,9 @@ test (void)
       babl_component ("B"),
       NULL
     ),
-    babl_pixel_format_new (
+    babl_format_new (
       "bar",
-      babl_model ("ycbcr"),
+      babl_model ("y'cbcr"),
       babl_type ("float"), 
       babl_component ("Y"),
       babl_component ("Cb"),
@@ -64,12 +64,12 @@ test (void)
     )
   );
 
-  babl_fish_process (fish, source_buf, temp_buf, PIXELS);
+  babl_process (fish, source_buf, temp_buf, PIXELS);
 
-  fish = babl_fish (babl_pixel_format ("bar"),
-                    babl_pixel_format ("foo"));
+  fish = babl_fish (babl_format ("bar"),
+                    babl_format ("foo"));
   
-  babl_fish_process (fish, temp_buf, destination_buf, PIXELS);
+  babl_process (fish, temp_buf, destination_buf, PIXELS);
 
   for (i=0; i<PIXELS * 3; i++)
     {
diff --git a/tests/srgb_to_lab_u8.c b/tests/srgb_to_lab_u8.c
new file mode 100644 (file)
index 0000000..bea2c6d
--- /dev/null
@@ -0,0 +1,78 @@
+/* babl - dynamically extendable universal pixel conversion library.
+ * Copyright (C) 2005, Øyvind Kolås.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <math.h>
+#include "babl.h"
+#include "babl-internal.h"
+
+#define PIXELS    6
+#define TOLERANCE 0
+
+unsigned char source_buf [PIXELS*3]=
+  {  0,   0,   0,
+   127, 127, 127,
+   255, 255, 255,
+   255, 0.0, 0.0,
+   0.0, 255, 0.0,
+   0.0, 0.0, 255};
+
+unsigned char reference_buf [PIXELS*3]=
+  {  0,   0,   0,
+   127,   0,   0,
+   255, 255, 255,
+     0,   0,   0,
+     0,   0,   0,
+     0,   0,   0};
+
+unsigned char destination_buf [PIXELS*3];
+
+int
+test (void)
+{
+  int   i;
+  int   OK=1;
+  babl_process (babl_fish ("srgb", "cie-lab-u8"),
+                source_buf, destination_buf,
+                PIXELS);
+  
+  for (i=0; i<PIXELS * 3; i++)
+    {
+      if ((destination_buf[i] - reference_buf[i]) > TOLERANCE)
+        {
+          babl_log ("%2i (%2i%%3=%i, %2i/3=%i) is %i should be %i",
+                      i, i,i%3,    i,i/3,  destination_buf[i], reference_buf[i]);
+          OK=0;
+        }
+    }
+  if (!OK)
+    return -1;
+  return 0;
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+  babl_init ();
+  if (test())
+    return -1;
+  babl_destroy ();
+  return 0;
+}
index 7ffa2cba6efed1a7fef1da3e9e2ec4e169dc6b18..e33fb72255392728f1c486f77120631bdac904f7 100644 (file)
@@ -37,14 +37,14 @@ test (void)
 
   
   fish = babl_fish (
-    babl_pixel_format_new (
+    babl_format_new (
       "foo",
       babl_model ("gray"),
       babl_type ("u8"),
       babl_component ("Y"),
       NULL
     ),
-    babl_pixel_format_new (
+    babl_format_new (
       "bar",
       babl_model ("gray"),
       babl_type ("float"),
@@ -52,7 +52,7 @@ test (void)
       NULL
     ));
 
-  babl_fish_process (fish, 
+  babl_process (fish, 
      u8_buf, float_buf, 
      BUFFER_LENGTH);